#ifndef CONSTRAINTSWINDOW_H_
#define CONSTRAINTSWINDOW_H_

#include <gtkmm/dialog.h>
#include <gtkmm/button.h>
#include <gtkmm/treeview.h>
#include <gtkmm/treestore.h>
#include <libglademm.h>
#include <boost/shared_ptr.hpp>
#include "../constraint.h"

/// The constraints dialog.  This window displays the constraints set, and
/// provides means for manipulating the constraints.
class ConstraintsWindow : public Gtk::Dialog {
public:
	ConstraintsWindow(BaseObjectType*, const Glib::RefPtr<Gnome::Glade::Xml>&);
	virtual ~ConstraintsWindow();

    boost::shared_ptr<Constraint> constraints() const;

protected:
	//Signal handlers:
	virtual void on_cancel();
	virtual void on_ok();
    virtual void on_add_constraint();
    virtual void on_remove_constraint();
    virtual void on_clear_constraints();
	virtual bool on_delete_event(GdkEventAny*);

private:
	// the ModelColumns class describes the treeview's columns layout.
	struct TypeModelColumns : public Gtk::TreeModel::ColumnRecord {
		TypeModelColumns() { add(type); }

		Gtk::TreeModelColumn<Glib::ustring> type;
	};

	// the ModelColumns class describes the treeview's columns layout.
	struct ConstraintsModelColumns : public Gtk::TreeModel::ColumnRecord {
		ConstraintsModelColumns() { add(type); add(value); }

		Gtk::TreeModelColumn<Glib::ustring> type;
        Gtk::TreeModelColumn<Glib::ustring> value;
	};

    boost::shared_ptr<Constraint> constraints_;

	//Member widgets:
	Gtk::Button* cancel_button_;
	Gtk::Button* ok_button_;
	Gtk::Button* add_constraint_button_;
	Gtk::Button* remove_constraint_button_;
	Gtk::Button* clear_constraints_button_;
	Gtk::TreeView* constraint_types_treeview_;
	TypeModelColumns constraint_types_treeview_columns_;
	Gtk::TreeView* constraints_treeview_;
	ConstraintsModelColumns constraints_treeview_columns_;
	Glib::RefPtr<Gtk::TreeStore> constraint_types_treeview_model_;
	Glib::RefPtr<Gtk::TreeStore> constraints_treeview_model_;

    // Helper functions
private:
    void init_types_treeview();
    void init_constraints_treeview();
    void constraints(boost::shared_ptr<Constraint> constraint);
};

#endif
